import store from './store/index'
import group_m from './util/groupData'
import socket_m from './util/connect'

let rightMenuList = []
let data1

let list1 = [{
  id: '1-1',
  con: "置顶",
  disabled: true
},
{
  id: '1-2',
  con: "删除聊天"
}]

let list2 = [{
  id: '2-1',
  con: "复制",
  disabled: true
},
{
  id: '2-2',
  con: "撤回",
},]

function showList(id, arg1) {
  rightMenuList.length = 0
  data1 = arg1
  switch (id) {
    case 1:
      list1.forEach(item => rightMenuList.push(item))
      break
    case 2:
      list2.forEach(item => rightMenuList.push(item))
      break
  }
}

async function menuClick_fn(id) {
  switch (id) {
    case '1-1':
      break

    case '1-2':
      var num = store.state.rightMenuActiveGroupNum - 0
      socket_m.sendMsg('deleteTempGroup', { num }, o => {
        console.log(num, o);
        if (o.code === 0) {
          group_m.deleteList(num)
        }
      })
      break
    case '2-1':
      break
    case '2-2':
      var num = store.state.chat.groupNum
      var id = data1
      socket_m.sendMsg('groupWithDraw', { num, id }, o => {
        console.log(o);
        if (o.code === 0) {
          let item = group_m.groupList.find(item1 => item1.num === num)
          if (item) {
            let message = item.messages.find(item2 => item2.id === id)
            if (message) {
              message.isWithDraw = true
              message.con = ''
              message.imgUrl = ''
              console.log(message);
            }
          }
        }
      })
      break
  }
}

export default {
  rightMenuList,
  menuClick_fn,
  showList
}